package classes.managers {
	import classes.buttons.BaseButton;
	import classes.scenes.A_Scene;
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	import classes.global.GlobalProperties;
	
	/**
	 * ...
	 * @author Kihoonee
	 */
	public class Rank_Manager extends A_Scene {
		
		private var retryBtn:BaseButton;
		private var endBtn:BaseButton;
		
		public function Rank_Manager( _main:Main, _mc:MovieClip ) {
			super( _main, _mc );
			
			addEvent();
		}
		
		public function myData( _xml:XML ):void {
			//trace("myData : ",_xml)
			mc.id_txt.text = GlobalProperties.nick;
			mc.score_txt.text = split(GlobalProperties.score);
			mc.rank_txt.text = _xml.rank;
		}
		
		public function rankData( _xml:XML ):void {
			//trace("rankData : ", _xml)
			var i:int;
			var length:int = _xml.row.length();
			for (i = 0; i < length; i++) {
				if ( _xml.row.nick[i] == null ) {
					
				}else {
					if ( i < 10 ) {
						mc["no" + (i + 1) + "_txt"].text = _xml.row.nick[i];
						mc["no" + (i + 1) + "_score"].text = split(_xml.row.score[i]);
					}else {
						switch (i) {
							case 10: mc["no" + (i + 1) + "_txt"].text = _xml.row.nick[i]; mc["no" + (i + 1) + "_score"].text = split(_xml.row.score[i]);
							break;
							case 20: mc["no" + (i + 1) + "_txt"].text = _xml.row.nick[i]; mc["no" + (i + 1) + "_score"].text = split(_xml.row.score[i]);
							break;
							case 30: mc["no" + (i + 1) + "_txt"].text = _xml.row.nick[i]; mc["no" + (i + 1) + "_score"].text = split(_xml.row.score[i]);
							break;
							case 40: mc["no" + (i + 1) + "_txt"].text = _xml.row.nick[i]; mc["no" + (i + 1) + "_score"].text = split(_xml.row.score[i]);
							break;
							case 50: mc["no" + (i + 1) + "_txt"].text = _xml.row.nick[i]; mc["no" + (i + 1) + "_score"].text = split(_xml.row.score[i]);
							break;
							case 60: mc["no" + (i + 1) + "_txt"].text = _xml.row.nick[i]; mc["no" + (i + 1) + "_score"].text = split(_xml.row.score[i]);
							break;
							case 70: mc["no" + (i + 1) + "_txt"].text = _xml.row.nick[i]; mc["no" + (i + 1) + "_score"].text = split(_xml.row.score[i]);
							break;
							case 80: mc["no" + (i + 1) + "_txt"].text = _xml.row.nick[i]; mc["no" + (i + 1) + "_score"].text = split(_xml.row.score[i]);
							break;
							case 90: mc["no" + (i + 1) + "_txt"].text = _xml.row.nick[i]; mc["no" + (i + 1) + "_score"].text = split(_xml.row.score[i]);
							break;
							case 100: mc["no" + (i + 1) + "_txt"].text = _xml.row.nick[i]; mc["no" + (i + 1) + "_score"].text = split(_xml.row.score[i]);
							break;
							default:
						}
					}
				}
			}
		}
		
		private function split( _str:String ):String {
			trace(_str)
			var day:String = _str.substr(0, 2);
			var hour:String = _str.substr(2, 2);
			var min:String = _str.substr(4, 2);
			var sec:String = _str.substr(6, 2);
			var milSec:String = _str.substr(8, 2);
			
			var score:String = day +" 일" + hour + " 시간" + min + " 분" + sec + " 초" + milSec;
			
			return score
		}
		
		private function addEvent():void {
			retryBtn = new BaseButton( mc.retry_btn );
			retryBtn.addEventListener(MouseEvent.CLICK, btnEvent );
			
			endBtn = new BaseButton( mc.end_btn );
			endBtn.addEventListener(MouseEvent.CLICK, btnEvent );
		}
		
		private function btnEvent(e:MouseEvent):void {
			if ( e.target.name == "retry_btn" ) {
				main.retry();
			}else if ( e.target.name == "end_btn" ) {
				main.end();
			}
		}
		
	}

}